package cn.fl.bizflow.controller;

import cmm.comm.facade.framework.api.ISysDictionaryApiService;
import cmm.comm.facade.framework.dto.SysDictionaryDTO;
import cmm.mid.core.framework.page.DataResultVO;
import cmm.mid.core.framework.page.KeyValueVO;
import cmm.user.facade.system.api.ISysOrgApiService;
import cmm.user.facade.system.dto.SysOrgDTO;
import cmm.web.core.framework.controller.BaseController;
import cn.cmm.base.framework.constant.BaseConstant;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.bizflow.service.ISysBizFlowRlService;
import cn.fl.bizflow.vo.SysBizFlowRlVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.system.constant.SysLogConstant;
import com.alibaba.fastjson.JSONObject;
import fl.flow.facade.flow.api.IFlowQueryApiService;
import fl.flow.facade.flow.condition.SysFlowSHQueryCondition;
import fl.flow.facade.flow.constant.FlowConstant;
import fl.flow.facade.flow.dto.SysFlowSHDTO;
import fl.spl.facade.bizflow.condition.SysBizFlowRlQC;
import fl.spl.facade.bizflow.constant.SysBizFlowRlConstant;
import fl.spl.facade.framework.constant.SplSystemConstant;
import fl.spl.facade.framework.enums.SplAudStsCdEnum;
import fl.spl.facade.framework.enums.bizflow.SplBizFlowRelEnum;
import fl.spl.facade.spl.constant.SplInfoConstant;
import net.sf.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;

/**
 * @Description: 业务数据与流程权限关系表 控制层
 */
@Controller
@RequestMapping("/bizflow/sysBizFlowRl")
public class SysBizFlowRlController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(SysBizFlowRlController.class);

    /**
     * SysBizFlowRl 服务层BEAN
     */
    @Autowired
    private ISysBizFlowRlService sysBizFlowRlService;

    @Autowired
    private ISysDictionaryApiService sysDictionaryApiService;
    /**
     * 流程历史记录服务
     */
    @Autowired
    private IFlowQueryApiService flowQueryApiService;

    @Autowired
    private ISysOrgApiService sysOrgApiService;

    /**
     * 到新增/修改页面
     */
    @RequestMapping(value = "/toAddPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddPage(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView view = new ModelAndView("bizflow/sysBizFlowRl/sysBizFlowRlAddPage2");

        String dataId = request.getParameter("dataId");//业务数据ID
        String tabNm = request.getParameter("tabNm");//业务数据表名
        String codeGrpCd = request.getParameter("codeGrpCd");//数据字典组
        String saveBizFlowRl = request.getParameter("saveBizFlowRl");//是否允许修改业务数据与流程权限关系
        String saveNoSpNum = request.getParameter("saveNoSpNum");
        String currBuOrgCd = request.getParameter("currBuOrgCd");
        String isFlow = request.getParameter("isFlow");
        String isShowSave = request.getParameter("isShowSave") ;

        if (StringUtils.isNotEmpty(isFlow) && isFlow.equals(BaseConstant.IS_YESNO_YES_STR)) {
            /*SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
            List<Long> idList = new ArrayList<Long>();
            idList.add(Long.valueOf(dataId));
            flowQc.setDataIdList(idList);
            flowQc.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
            flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            flowQc.setStatus(BaseConstant.IS_YESNO_YES);
            List<String> busTypList = new ArrayList<String>();
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SPL_AUTHORITH);
            busTypList.add(FlowConstant.FLOW_MODEL_TYP_SPL_AUTHORITH);
            flowQc.setBusTypList(busTypList);
            List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
            SysFlowSHDTO sysFlowSHDTO = null;
            if (CollectionUtils.isNotEmpty(flowSHList)) {
                sysFlowSHDTO = flowSHList.get(0);
                currBuOrgCd = sysFlowSHDTO.getBuOrgCd();
            }*/
        }else{
            if (StringUtils.isEmpty(currBuOrgCd)) {
                currBuOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
            }
        }
        view.addObject("dataId", dataId);
        view.addObject("tabNm", tabNm);
        view.addObject("codeGrpCd", codeGrpCd);
        view.addObject("saveBizFlowRl", saveBizFlowRl);
        view.addObject("saveNoSpNum", saveNoSpNum);
        view.addObject("currBuOrgCd", currBuOrgCd);
        view.addObject("isFlow", isFlow);
        if(StringUtils.isNotEmpty(isShowSave)){
            view.addObject("isShowSave",Integer.parseInt(isShowSave));
        }else{
            view.addObject("isShowSave",0);
        }

        BaseLogUtils.info(logger, "toAddPage", "跳转到新增/修改页面.[dataId=" + dataId + ",tabNm=" + tabNm + "]", CurrentThreadContext.getCurrentUserName());

        //事业部流程权限配置Dictionary
        List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCd);

        JSONObject buOrgCdJson = new JSONObject();
        List<KeyValueVO> kvList = null;
        JSONObject keyVal = new JSONObject();
        if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
            boolean isAuth = false;
            for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                if (!SplSystemConstant.DEFAULT_ORG_CD.equals(currBuOrgCd) && sysDictionaryDTO.getCodeDesc().equals(currBuOrgCd)) {
                    isAuth = true;
                    if(StringUtils.isNotEmpty(isFlow) && BaseConstant.IS_YESNO_YES_STR.equals(isFlow)){
                        if(CurrentThreadContext.getCurrentBuOrgCd().equals(currBuOrgCd)){
                            view.addObject("isShowSave",1);
                        }
                    }else{
                        view.addObject("isShowSave",1);
                    }
                    break;
                }
            }
            if (SplSystemConstant.DEFAULT_ORG_CD.equals(currBuOrgCd) || isAuth) {
                //查询所有事业部CODE与名称-Map
                List<SysOrgDTO> dtoList = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getFlServiceSysCd());
                Map<String, String> buOrgCdNmMap = null;
                if (CollectionUtils.isNotEmpty(dtoList)) {
                    buOrgCdNmMap = new HashMap<>(dtoList.size());
                    for (SysOrgDTO dto : dtoList) {
                        buOrgCdNmMap.put(dto.getOrgCd(), dto.getOrgDispNm());
                    }
                }
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    if (isAuth && !sysDictionaryDTO.getCodeDesc().equals(currBuOrgCd)) {
                        continue;
                    }
                    if (keyVal.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        kvList = (List<KeyValueVO>) keyVal.get(sysDictionaryDTO.getCodeDesc());
                    } else {
                        kvList = new ArrayList<>();
                    }
                    kvList.add(keyValueVO);
                    keyVal.put(sysDictionaryDTO.getCodeDesc(), kvList);
                    if (!buOrgCdJson.containsKey(sysDictionaryDTO.getCodeDesc()) && null != buOrgCdNmMap && buOrgCdNmMap.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCdJson.put(sysDictionaryDTO.getCodeDesc(), buOrgCdNmMap.get(sysDictionaryDTO.getCodeDesc()));
                    }
                }
            }
        }
        view.addObject("buOrgCdJson", buOrgCdJson);
        view.addObject("sysBizFlowJson", keyVal);

        BaseLogUtils.info(logger, "toAddPage", "修改页面,获取数据.[" + JSONObject.toJSONString(view) + "]", CurrentThreadContext.getCurrentUserName());

        return view;
    }

    /**
     * 到新增/修改页面
     */
    @RequestMapping(value = "/toAddAndApplyPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toAddAndApplyPage(HttpServletRequest request, HttpServletResponse response) {
        String dataId = request.getParameter("dataId");//业务数据ID
        String tabNm = request.getParameter("tabNm");//业务数据表名
        String codeGrpCd = request.getParameter("codeGrpCd");//数据字典组
        String saveBizFlowRl = request.getParameter("saveBizFlowRl");//是否允许修改业务数据与流程权限关系
        String saveNoSpNum = request.getParameter("saveNoSpNum");
        ModelAndView view = new ModelAndView("bizflow/sysBizFlowRl/sysBizFlowRlAddPage3");
        //查找已发起的流程
        //查找流程发起时的期数
	    /*SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
		List<Long> idList  = new ArrayList<Long>();
		idList.add(Long.valueOf(dataId));
		flowQc.setDataIdList(idList);
		flowQc.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
		flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
		flowQc.setStatus(BaseConstant.IS_YESNO_YES);
		List<String> busTypList = new ArrayList<String>();
		busTypList.add(FlowConstant.FLOW_MODEL_TYP_SPL_AUTHORITH);
        busTypList.add(SysBizFlowRlConstant.CODE_SPL_BIZ_FLOW_APPLY_QK_FLOW_CD);
        flowQc.setBusTypList(busTypList);
		List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
		SysFlowSHDTO sysFlowSHDTO = null;
		if(CollectionUtils.isNotEmpty(flowSHList)){
			sysFlowSHDTO = flowSHList.get(0);
			String audStsCd = flowSHList.get(0).getAudStsCd();
			if(audStsCd.equals(FlowConstant.FLOW_CHECK_STATE_NON)||audStsCd.equals(FlowConstant.FLOW_CHECK_STATE_NO_PASS)||audStsCd.equals(FlowConstant.FLOW_CHECK_STATE_PASS)){
				saveBizFlowRl =String.valueOf((BaseConstant.IS_YESNO_YES));
				saveNoSpNum = String.valueOf((BaseConstant.IS_YESNO_YES));
			}else{
				saveBizFlowRl =String.valueOf((BaseConstant.IS_YESNO_NO));
				saveNoSpNum = String.valueOf((BaseConstant.IS_YESNO_NO));
			}
		}*/
		/*view.addObject("sysFlowSHDTO",sysFlowSHDTO);
		view.addObject("sysFlowSH",com.alibaba.fastjson.JSON.toJSONString(sysFlowSHDTO));
		view.addObject("pNo", sysFlowSHDTO==null?"":sysFlowSHDTO.getPNo());*/
        view.addObject("dataId", dataId);
        view.addObject("tabNm", tabNm);
        view.addObject("codeGrpCd", codeGrpCd);
        view.addObject("saveBizFlowRl", saveBizFlowRl);
        view.addObject("saveNoSpNum", saveNoSpNum);
        view.addObject("isShowSave",0);

        String audStsCd = request.getParameter("audStsCd");
        if(StringUtils.isNotEmpty(audStsCd) && (SplAudStsCdEnum.CHECKING.getStatus().equals(audStsCd)
                || SplAudStsCdEnum.REJECT.getStatus().equals(audStsCd))){
            view.addObject("isFlow",BaseConstant.IS_YESNO_YES);
        }else{
            view.addObject("isFlow",BaseConstant.IS_YESNO_NO);
        }

        BaseLogUtils.info(logger, "toAddPage", "跳转到新增/修改页面.[dataId=" + dataId + ",tabNm=" + tabNm + "]", CurrentThreadContext.getCurrentUserName());

        view.addObject("currBuOrgCd", CurrentThreadContext.getCurrentBuOrgCd());

        //事业部流程权限配置Dictionary
        List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCd);

        JSONObject buOrgCdJson = new JSONObject();
        List<KeyValueVO> kvList = null;
        JSONObject keyVal = new JSONObject();
        if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
            boolean isAuth = false;
            for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                if (sysDictionaryDTO.getCodeDesc().equals(CurrentThreadContext.getCurrentBuOrgCd())) {
                    isAuth = true;
                    break;
                }
            }
            if (SplSystemConstant.DEFAULT_ORG_CD.equals(CurrentThreadContext.getCurrentBuOrgCd()) || isAuth) {
                //查询所有事业部CODE与名称-Map
                List<SysOrgDTO> dtoList = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getFlServiceSysCd());
                Map<String, String> buOrgCdNmMap = null;
                if (CollectionUtils.isNotEmpty(dtoList)) {
                    buOrgCdNmMap = new HashMap<>(dtoList.size());
                    for (SysOrgDTO dto : dtoList) {
                        buOrgCdNmMap.put(dto.getOrgCd(), dto.getOrgDispNm());
                    }
                }
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    if (isAuth && !sysDictionaryDTO.getCodeDesc().equals(CurrentThreadContext.getCurrentBuOrgCd())) {
                        continue;
                    }
                    if (keyVal.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        kvList = (List<KeyValueVO>) keyVal.get(sysDictionaryDTO.getCodeDesc());
                    } else {
                        kvList = new ArrayList<>();
                    }
                    kvList.add(keyValueVO);
                    keyVal.put(sysDictionaryDTO.getCodeDesc(), kvList);
                    if (!buOrgCdJson.containsKey(sysDictionaryDTO.getCodeDesc()) && null != buOrgCdNmMap && buOrgCdNmMap.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCdJson.put(sysDictionaryDTO.getCodeDesc(), buOrgCdNmMap.get(sysDictionaryDTO.getCodeDesc()));
                    }
                }
                view.addObject("isShowSave",1);
            }
        }
        view.addObject("buOrgCdJson", buOrgCdJson);
        view.addObject("sysBizFlowJson", keyVal);
        BaseLogUtils.info(logger, "toAddAndApplyPage", "修改页面,获取数据.[" + JSONObject.toJSONString(view) + "]", CurrentThreadContext.getCurrentUserName());
        return view;
    }

    @RequestMapping(value = "/toDetailPage.do", method = {RequestMethod.GET, RequestMethod.POST})
    public ModelAndView toDetailPage(HttpServletRequest request, HttpServletResponse response) {
        String dataId = request.getParameter("dataId");//业务数据ID
        String tabNm = request.getParameter("tabNm");//业务数据表名
        String codeGrpCd = request.getParameter("codeGrpCd");//数据字典组
        String saveBizFlowRl = request.getParameter("saveBizFlowRl");//是否允许修改业务数据与流程权限关系
        String saveNoSpNum = request.getParameter("saveNoSpNum");
        String currBuOrgCd = request.getParameter("currBuOrgCd");
        ModelAndView view = new ModelAndView("bizflow/sysBizFlowRl/sysBizFlowRlDetailPage");
        view.addObject("dataId", dataId);
        view.addObject("tabNm", tabNm);
        view.addObject("codeGrpCd", codeGrpCd);
        view.addObject("saveBizFlowRl", saveBizFlowRl);
        view.addObject("saveNoSpNum", saveNoSpNum);
        BaseLogUtils.info(logger, "toAddPage", "跳转到新增/修改页面.[dataId=" + dataId + ",tabNm=" + tabNm + "]", CurrentThreadContext.getCurrentUserName());

//        List<KeyValueVO> kvList = this.getKvList(codeGrpCd);
//        view.addObject("kvList", kvList);
//        view.addObject("kvListJSON", JSONArray.fromObject(kvList));
        if(StringUtils.isEmpty(currBuOrgCd)){
            currBuOrgCd = CurrentThreadContext.getCurrentBuOrgCd() ;
        }
        view.addObject("currBuOrgCd", currBuOrgCd);

        String audStsCd = request.getParameter("audStsCd");
        if(StringUtils.isNotEmpty(audStsCd) && (SplAudStsCdEnum.CHECKING.getStatus().equals(audStsCd)
                || SplAudStsCdEnum.REJECT.getStatus().equals(audStsCd))){
            view.addObject("isFlow",BaseConstant.IS_YESNO_YES);
        }else{
            view.addObject("isFlow",BaseConstant.IS_YESNO_NO);
        }

        //事业部流程权限配置Dictionary
        List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCd);

        JSONObject buOrgCdJson = new JSONObject();
        List<KeyValueVO> kvList = null;
        JSONObject keyVal = new JSONObject();
        if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
            boolean isAuth = false;
            for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                if (sysDictionaryDTO.getCodeDesc().equals(currBuOrgCd)) {
                    isAuth = true;
                    break;
                }
            }
            if (SplSystemConstant.DEFAULT_ORG_CD.equals(currBuOrgCd) || isAuth) {
                //查询所有事业部CODE与名称-Map
                List<SysOrgDTO> dtoList = this.sysOrgApiService.searchListByOrgTypCd(CurrentThreadContext.getFlServiceSysCd());
                Map<String, String> buOrgCdNmMap = null;
                if (CollectionUtils.isNotEmpty(dtoList)) {
                    buOrgCdNmMap = new HashMap<>(dtoList.size());
                    for (SysOrgDTO dto : dtoList) {
                        buOrgCdNmMap.put(dto.getOrgCd(), dto.getOrgDispNm());
                    }
                }
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    if (isAuth && !sysDictionaryDTO.getCodeDesc().equals(currBuOrgCd)) {
                        continue;
                    }
                    if (keyVal.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        kvList = (List<KeyValueVO>) keyVal.get(sysDictionaryDTO.getCodeDesc());
                    } else {
                        kvList = new ArrayList<>();
                    }
                    kvList.add(keyValueVO);
                    keyVal.put(sysDictionaryDTO.getCodeDesc(), kvList);
                    if (!buOrgCdJson.containsKey(sysDictionaryDTO.getCodeDesc()) && null != buOrgCdNmMap && buOrgCdNmMap.containsKey(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCdJson.put(sysDictionaryDTO.getCodeDesc(), buOrgCdNmMap.get(sysDictionaryDTO.getCodeDesc()));
                    }
                }
                view.addObject("isShowSave",1);
            }
        }
        view.addObject("buOrgCdJson", buOrgCdJson);
        view.addObject("sysBizFlowJson", keyVal);
        BaseLogUtils.info(logger, "toDetailPage", "详情页面,获取数据.[" + JSONObject.toJSONString(view) + "]", CurrentThreadContext.getCurrentUserName());
        return view;
    }

    /**
     * 根据字典中代码组值获取组员集合
     *
     * @param grpCd 代码组值
     * @return 集合
     */
    private List<KeyValueVO> getKvList(String grpCd) {
        List<KeyValueVO> kvList = new ArrayList<>();
        try {
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), grpCd);
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    KeyValueVO keyValueVO = new KeyValueVO();
                    keyValueVO.setKey(sysDictionaryDTO.getCode());
                    keyValueVO.setValue(sysDictionaryDTO.getCodeNm());
                    kvList.add(keyValueVO);
                }
            }
        } catch (BaseException e) {
            BaseLogUtils.info(logger, "getKvList", "获取字典项组" + grpCd + "失败.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception e) {
            BaseLogUtils.error(logger, "getKvList", "获取字典项组" + grpCd + "失败,系统错误.ERROR:" + e.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        return kvList;
    }


    /**
     * 获取数据
     *
     * @param request
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getBizFlowRl.do", method = {RequestMethod.GET})
    @ResponseBody
    public Object getBizFlowRl(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        String dataId = request.getParameter("dataId");
        String tabNm = request.getParameter("tabNm");
        String currBuOrgCd = request.getParameter("currBuOrgCd") ;
        String isFlow = request.getParameter("isFlow");
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(tabNm)) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_DATA_PK_IS_EMPTY);
            BaseLogUtils.error(logger, "getBizFlowRl", "获取数据,参数不完整.[dataId=" + dataId + ",tabNm=" + tabNm + "]", CurrentThreadContext.getCurrentUserName());
            return result;
        }
        try {
            if(StringUtils.isNotEmpty(isFlow) && BaseConstant.IS_YESNO_YES_STR.equals(isFlow)){
                if(StringUtils.isEmpty(currBuOrgCd)){
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("获取经销商放款流程权限记录，事业部CODE为空.");
                    BaseLogUtils.error(logger, "getBizFlowRl", "获取经销商放款流程权限记录,事业部CODE为空.", CurrentThreadContext.getCurrentUserName());
                    return result;
                }
            }else{
                if(StringUtils.isEmpty(currBuOrgCd)){
                    currBuOrgCd = CurrentThreadContext.getCurrentBuOrgCd() ;
                }
            }
            SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
            List<Long> idList = new ArrayList<Long>();
            idList.add(Long.valueOf(dataId));
            flowQc.setDataIdList(idList);
            flowQc.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
            flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            flowQc.setStatus(BaseConstant.IS_YESNO_YES);
            List<String> buOrgCdList = new ArrayList<String>(1);
            buOrgCdList.add(currBuOrgCd) ;
            flowQc.setBusTypList(SplBizFlowRelEnum.getBusTypListByBuOrgCd(buOrgCdList));
            List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
            //事业部流程权限状态关系Map
            Map<String,String> buOrgCdAudStsCdMap = null ;
            if (CollectionUtils.isNotEmpty(flowSHList)) {
                buOrgCdAudStsCdMap = new HashMap<>(flowSHList.size()) ;
                for(SysFlowSHDTO sysFlowSHDTO : flowSHList){
                    if(!buOrgCdAudStsCdMap.containsKey(sysFlowSHDTO.getBuOrgCd())){
                        buOrgCdAudStsCdMap.put(sysFlowSHDTO.getBuOrgCd(),sysFlowSHDTO.getAudStsCd());
                    }
                }
            }

            List<String> buOrgCds = new ArrayList<>(4);
            //事业部流程权限配置Dictionary
            List<SysDictionaryDTO> sysDictionaryDTOS = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), SysBizFlowRlConstant.CODE_SPL_BIZ_FLOW_DIC_CD);
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOS)) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOS) {
                    if (!buOrgCds.contains(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCds.add(sysDictionaryDTO.getCodeDesc());
                    }
                }
            }
            SysBizFlowRlQC sysBizFlowRlQC = new SysBizFlowRlQC();
            sysBizFlowRlQC.setDataId(Long.valueOf(dataId));
            sysBizFlowRlQC.setTabNm(tabNm);
            sysBizFlowRlQC.setIsValid(BaseConstant.IS_YESNO_YES);
            sysBizFlowRlQC.setSysCd(StringUtils.isEmpty(CurrentThreadContext.getCurrentSysCd()) ? SplSystemConstant.FL_SYS_CD : CurrentThreadContext.getCurrentSysCd());
            List<SysBizFlowRlVO> list = null;
            if(SplSystemConstant.DEFAULT_ORG_CD.equals(currBuOrgCd)){
                sysBizFlowRlQC.setIsDel(BaseConstant.IS_YESNO_NO);
                List<String> flowingBuOrgCds = null ;
                if(null != buOrgCdAudStsCdMap){
                    flowingBuOrgCds = new ArrayList<>(buOrgCdAudStsCdMap.size()) ;
                    for(Map.Entry<String,String> buOrgCdAudStsCd : buOrgCdAudStsCdMap.entrySet()){
                        if (buOrgCdAudStsCd.getValue().equals(FlowConstant.FLOW_CHECK_STATE_IN) || buOrgCdAudStsCd.getValue().equals(FlowConstant.FLOW_CHECK_STATE_REJECT)) {
                            flowingBuOrgCds.add(buOrgCdAudStsCd.getKey()) ;
                            if(buOrgCds.contains(buOrgCdAudStsCd.getKey())){
                                buOrgCds.remove(buOrgCdAudStsCd.getKey()) ;
                            }
                        }
                    }
                    if(CollectionUtils.isNotEmpty(buOrgCds)){
                        sysBizFlowRlQC.setBuOrgCdList(buOrgCds);
                        if(null == list){
                            list = this.sysBizFlowRlService.searchList(sysBizFlowRlQC);
                        }
                    }
                    if(CollectionUtils.isNotEmpty(flowingBuOrgCds)){
                        if(StringUtils.isNotEmpty(isFlow) && BaseConstant.IS_YESNO_YES_STR.equals(isFlow)){
                            sysBizFlowRlQC.setIsDel(SysBizFlowRlConstant.CODE_FLOW_SAVE_STATUS);
                        }
                        sysBizFlowRlQC.setBuOrgCdList(flowingBuOrgCds);
                        if(null == list){
                            list = this.sysBizFlowRlService.searchList(sysBizFlowRlQC);
                        }else{
                            list.addAll(this.sysBizFlowRlService.searchList(sysBizFlowRlQC)) ;
                        }
                    }
                }else{
                    sysBizFlowRlQC.setIsDel(BaseConstant.IS_YESNO_NO);
                    sysBizFlowRlQC.setBuOrgCd(currBuOrgCd);
                    list = this.sysBizFlowRlService.searchList(sysBizFlowRlQC);
                }
            }else{
                if(buOrgCds.contains(currBuOrgCd)){
                    sysBizFlowRlQC.setIsDel(BaseConstant.IS_YESNO_NO);
                    if(null != buOrgCdAudStsCdMap){
                        for(Map.Entry<String,String> buOrgCdAudStsCd : buOrgCdAudStsCdMap.entrySet()){
                            if (buOrgCdAudStsCd.getKey().equals(currBuOrgCd) && (buOrgCdAudStsCd.getValue().equals(FlowConstant.FLOW_CHECK_STATE_IN) || buOrgCdAudStsCd.getValue().equals(FlowConstant.FLOW_CHECK_STATE_REJECT))) {
                                if(StringUtils.isNotEmpty(isFlow) && BaseConstant.IS_YESNO_YES_STR.equals(isFlow)){
                                    sysBizFlowRlQC.setIsDel(SysBizFlowRlConstant.CODE_FLOW_SAVE_STATUS);
                                    break;
                                }
                            }
                        }
                    }
                    sysBizFlowRlQC.setBuOrgCd(currBuOrgCd);
                    list = this.sysBizFlowRlService.searchList(sysBizFlowRlQC);
                }else{
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("获取经销商放款流程权限记录，无权限查看.");
                    BaseLogUtils.error(logger, "getBizFlowRl", "获取经销商放款流程权限记录,无权限查看.", CurrentThreadContext.getCurrentUserName());
                    return result;
                }
            }
            /*String pDefKey = "";
            if (CollectionUtils.isEmpty(list)) {
                sysBizFlowRlQC.setIsDel(BaseConstant.IS_YESNO_NO);
                list = this.sysBizFlowRlService.searchList(sysBizFlowRlQC);
            }
            if (CollectionUtils.isNotEmpty(list)) {
                for (SysBizFlowRlVO sysBizFlowRlVO : list) {
                    if (null != sysBizFlowRlVO && StringUtils.isNotEmpty(sysBizFlowRlVO.getPDefKey())) {
                        pDefKey += sysBizFlowRlVO.getPDefKey();
                        pDefKey += ";";
                    }
                }
                if (StringUtils.isNotEmpty(pDefKey)) {
                    pDefKey = pDefKey.substring(0, pDefKey.length() - 1);
                }
            }*/
            result.setData(list);
            BaseLogUtils.info(logger, "getBizFlowRl", "获取数据.[dataId=" + dataId + ",tabNm=" + tabNm + "]", CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "getBizFlowRl", "获取失败.[dataId=" + dataId + ",tabNm=" + tabNm + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.error(logger, "getBizFlowRl", "获取失败.[dataId=" + dataId + ",tabNm=" + tabNm + "]" + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }
        BaseLogUtils.error(logger, "getBizFlowRl", "获取经销商放款流程权限记录.result=[" + JSONObject.toJSONString(result) + "]", CurrentThreadContext.getCurrentUserName());
        return result;
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/addOrMdfBizFlowRl.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addOrMdfBizFlowRl(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_OPERATE_SUCC);
        List<SysBizFlowRlVO> list = null;
        String dataId = request.getParameter("dataId");
        String isFlow = request.getParameter("isFlow");
        String currBuOrgCd = request.getParameter("currBuOrgCd") ;
        try {
            list = this.getRequestForParamAdd(request);
            if(CollectionUtils.isEmpty(list)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("经销商流程放款权限数据为空！");
                return result ;
            }
            Map<String,List<SysBizFlowRlVO>> buOrgCdFLowRlMap = new HashMap<>(list.size()) ;
            List<SysBizFlowRlVO> sysBizFlowRlVOS = null ;
            for(SysBizFlowRlVO sysBizFlowRlVO : list){
                if(buOrgCdFLowRlMap.containsKey(sysBizFlowRlVO.getBuOrgCd())){
                    sysBizFlowRlVOS = buOrgCdFLowRlMap.get(sysBizFlowRlVO.getBuOrgCd());
                }else{
                    sysBizFlowRlVOS = new ArrayList<>(8);
                }
                sysBizFlowRlVOS.add(sysBizFlowRlVO);
                buOrgCdFLowRlMap.put(sysBizFlowRlVO.getBuOrgCd(),sysBizFlowRlVOS);
            }

            SysFlowSHQueryCondition flowQc = new SysFlowSHQueryCondition();
            flowQc.setDataId(Long.valueOf(dataId));
            flowQc.setWordsInTheTable(SplInfoConstant.SPL_FLOW_S_H_SPL);
            flowQc.setSysCd(CurrentThreadContext.getCurrentSysCd());
            flowQc.setStatus(BaseConstant.IS_YESNO_YES);
            List<String> buOrgCdList = new ArrayList<String>(BaseConstant.IS_YESNO_YES);
            buOrgCdList.add(currBuOrgCd) ;
            flowQc.setBusTypList(SplBizFlowRelEnum.getBusTypListByBuOrgCd(buOrgCdList));
            List<SysFlowSHDTO> flowSHList = this.flowQueryApiService.searchFlowSHList(flowQc);
            //事业部流程权限状态关系Map
            Map<String,Boolean> buOrgCdAudStsCdMap = null ;
            if (CollectionUtils.isNotEmpty(flowSHList)) {
                buOrgCdAudStsCdMap = new HashMap<>(flowSHList.size()) ;
                for(SysFlowSHDTO sysFlowSHDTO : flowSHList){
                    if(!buOrgCdAudStsCdMap.containsKey(sysFlowSHDTO.getBuOrgCd())){
                        if(sysFlowSHDTO.getAudStsCd().equals(SplAudStsCdEnum.CHECKING.getStatus()) || sysFlowSHDTO.getAudStsCd().equals(SplAudStsCdEnum.REJECT.getStatus())) {
                            buOrgCdAudStsCdMap.put(sysFlowSHDTO.getBuOrgCd(), true);
                        }else{
                            buOrgCdAudStsCdMap.put(sysFlowSHDTO.getBuOrgCd(), false);
                        }
                    }
                }
            }

            boolean success = false;
            List<String> buOrgCds = new ArrayList<>(4);
            //事业部流程权限配置Dictionary
            List<SysDictionaryDTO> sysDictionaryDTOS = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), SysBizFlowRlConstant.CODE_SPL_BIZ_FLOW_DIC_CD);
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOS)) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOS) {
                    if (!buOrgCds.contains(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCds.add(sysDictionaryDTO.getCodeDesc());
                    }
                }
            }
            if(SplSystemConstant.DEFAULT_ORG_CD.equals(currBuOrgCd)){
                //flag : true 流程权限审核中，false ： 未在流程中
                if(null == buOrgCdAudStsCdMap){
                    success = this.sysBizFlowRlService.batchAddBizFlowRlByBuOrgCd(buOrgCdFLowRlMap,buOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                }else{
                    List<String> flowBuOrgCds = new ArrayList<>(8);
                    List<String> noFlowBuOrgCds = new ArrayList<>(8);
                    for(String buOrgCd : buOrgCds){
                        if(buOrgCdAudStsCdMap.containsKey(buOrgCd) && buOrgCdAudStsCdMap.get(buOrgCd)){
                            flowBuOrgCds.add(buOrgCd);
                        }else{
                            noFlowBuOrgCds.add(buOrgCd) ;
                        }
                    }
                    if (CollectionUtils.isNotEmpty(flowBuOrgCds)) {
                        //插入流程中的数据信息
                        success = this.sysBizFlowRlService.batchAddBizFlowRlVOForFlow(buOrgCdFLowRlMap,flowBuOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                    }
                    if(CollectionUtils.isNotEmpty(noFlowBuOrgCds)){
                        success = this.sysBizFlowRlService.batchAddBizFlowRlByBuOrgCd(buOrgCdFLowRlMap,noFlowBuOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                    }
                }
            }else{
                if(buOrgCds.contains(currBuOrgCd)){
                    //flag : true 流程权限审核中，false ： 未在流程中
                    buOrgCds = new ArrayList<>(BaseConstant.IS_YESNO_YES);
                    buOrgCds.add(currBuOrgCd) ;
                    if(null == buOrgCdAudStsCdMap) {
                        success = this.sysBizFlowRlService.batchAddBizFlowRlByBuOrgCd(buOrgCdFLowRlMap,buOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                    }else{
                        if(buOrgCdAudStsCdMap.containsKey(currBuOrgCd) && buOrgCdAudStsCdMap.get(currBuOrgCd)){
                            //插入流程中的数据信息
                            success = this.sysBizFlowRlService.batchAddBizFlowRlVOForFlow(buOrgCdFLowRlMap,buOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                        }else{
                            success = this.sysBizFlowRlService.batchAddBizFlowRlByBuOrgCd(buOrgCdFLowRlMap,buOrgCds,CurrentThreadContext.getCurrentSysCd(),CurrentThreadContext.getCurrentUserName());
                        }
                    }
                }else{
                    success = false ;
                }
            }
            if (!success) {
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo(SysLogConstant.LOG_CMM_OPERATE_FAIL);
            }
            BaseLogUtils.info(logger, "addOrMdfBizFlowRl", "新增数据.result:" + success + ",DATA:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addOrMdfBizFlowRl", "新增数据失败.DATA:" + JSONObject.toJSONString(list) + ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            BaseLogUtils.info(logger, "addOrMdfBizFlowRl", "新增数据失败.DATA:" + JSONObject.toJSONString(list) + ex.getMessage(), CurrentThreadContext.getCurrentUserName(),ex);
        }

        return result;
    }

    /**
     * 新增并发起流程
     */
    @RequestMapping(value = "/addAndApply.do", method = {RequestMethod.POST})
    @ResponseBody
    public Object addAndApply(HttpServletRequest request, HttpServletResponse response) throws BaseException {
        DataResultVO result = new DataResultVO(BaseConstant.IS_YESNO_YES, SysLogConstant.LOG_CMM_ADD_SUCC);
        List<SysBizFlowRlVO> list = null;
        Long id = null;
        try {
            String splId = request.getParameter("dataId");
            String buOrgCd = request.getParameter("currBuOrgCd");
            String codeGrpCd = request.getParameter("codeGrpCd") ;
            if(StringUtils.isEmpty(codeGrpCd)){
                codeGrpCd = SysBizFlowRlConstant.CODE_SPL_BIZ_FLOW_DIC_CD ;
            }

            list = this.getRequestForParamAdd(request);
            if(CollectionUtils.isEmpty(list)){
                result.setSuccess(BaseConstant.IS_YESNO_NO);
                result.setInfo("经销商流程放款权限数据为空！");
                return result ;
            }
            List<String> buOrgCds = new ArrayList<>(4);
            //事业部流程权限配置Dictionary
            List<SysDictionaryDTO> sysDictionaryDTOS = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCd);
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOS)) {
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOS) {
                    if (!buOrgCds.contains(sysDictionaryDTO.getCodeDesc())) {
                        buOrgCds.add(sysDictionaryDTO.getCodeDesc());
                    }
                }
            }
            Map<String,List<SysBizFlowRlVO>> buOrgCdFLowRlMap = new HashMap<>(list.size()) ;
            List<SysBizFlowRlVO> sysBizFlowRlVOS = null ;
            for(SysBizFlowRlVO sysBizFlowRlVO : list){
                if(buOrgCdFLowRlMap.containsKey(sysBizFlowRlVO.getBuOrgCd())){
                    sysBizFlowRlVOS = buOrgCdFLowRlMap.get(sysBizFlowRlVO.getBuOrgCd());
                }else{
                    sysBizFlowRlVOS = new ArrayList<>(8);
                }
                sysBizFlowRlVOS.add(sysBizFlowRlVO);
                buOrgCdFLowRlMap.put(sysBizFlowRlVO.getBuOrgCd(),sysBizFlowRlVOS);
            }

            if(StringUtils.isNotEmpty(buOrgCd) && buOrgCd.equals(SplSystemConstant.DEFAULT_ORG_CD)){

            }else{
                if(CollectionUtils.isEmpty(buOrgCds) || !buOrgCds.contains(buOrgCd)){
                    result.setSuccess(BaseConstant.IS_YESNO_NO);
                    result.setInfo("您所在部门暂时不支持修改经销商放款权限变更.");
                    return result ;
                }
            }
            BaseLogUtils.info(logger, "addAndApply", "供应商流程权限变更参数获取==>" + JSONObject.toJSONString(list));

            //流程权限变更，支持未上牌资产数量，及超期30天未上牌车辆数量
            List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(SplSystemConstant.SPL_SYS_CD, CurrentThreadContext.getCurrentOrgCd(), SplSystemConstant.SPL_FLOW_AUTH_CONFIG_DIC_CD);

            //流程编号-数据字典CODE map
            Map<String, SysDictionaryDTO> flowNoAndSysDicMap = null;
            if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
                flowNoAndSysDicMap = new HashMap<>(sysDictionaryDTOList.size());
                for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                    if (StringUtils.isNotEmpty(sysDictionaryDTO.getCodeAttr1()) || StringUtils.isNotEmpty(sysDictionaryDTO.getCodeAttr2())) {
                        flowNoAndSysDicMap.put(sysDictionaryDTO.getCode(), sysDictionaryDTO);
                    }
                }
            }

            result = this.sysBizFlowRlService.addAndApplySplBizFlowRl(buOrgCdFLowRlMap, Long.valueOf(splId), flowNoAndSysDicMap,buOrgCd);
            result.setData(id);
            BaseLogUtils.info(logger, "add", "新增数据.[id=" + id + "] DATA:" + JSONObject.toJSONString(list), CurrentThreadContext.getCurrentUserName());
        } catch (BaseException ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(ex.getMessage());
            ex.printStackTrace();
            BaseLogUtils.info(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(list) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        } catch (Exception ex) {
            result.setSuccess(BaseConstant.IS_YESNO_NO);
            result.setInfo(SysLogConstant.LOG_CMM_SYS_ERROR);
            BaseLogUtils.error(logger, "add", "新增数据失败.DATA:" + JSONObject.toJSONString(list) + ex.getMessage(), CurrentThreadContext.getCurrentUserName());
        }

        return result;
    }

    /**
     * 获取请求参数
     *
     * @param request
     * @return
     * @throws BaseException
     */
    private List<SysBizFlowRlVO> getRequestParam(HttpServletRequest request) throws BaseException {
        List<SysBizFlowRlVO> list = new ArrayList<SysBizFlowRlVO>();
        String dataId = request.getParameter("dataId");
        String tabNm = request.getParameter("tabNm");
        String currBuOrgCd = request.getParameter("currBuOrgCd");
        String isFlow = request.getParameter("isFLow");
        String codeGrpCd = request.getParameter("codeGrpCd");
        if (StringUtils.isEmpty(codeGrpCd)) {
            codeGrpCd = SysBizFlowRlConstant.CODE_SPL_BIZ_FLOW_DIC_CD;
        }
        if (StringUtils.isEmpty(dataId) || StringUtils.isEmpty(tabNm)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请求参数不完整.");
        }

        if (StringUtils.isNotEmpty(isFlow) && BaseConstant.IS_YESNO_YES_STR.equals(isFlow)) {
            if (StringUtils.isEmpty(currBuOrgCd)) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "流程权限变更流程中，事业部CODE参数不能为空.");
            }
        } else {
            if (StringUtils.isEmpty(currBuOrgCd)) {
                currBuOrgCd = CurrentThreadContext.getCurrentBuOrgCd();
            }
        }
        List<String> buOrgCds = new ArrayList<>(4);
        //事业部流程权限配置Dictionary
        List<SysDictionaryDTO> sysDictionaryDTOList = this.sysDictionaryApiService.searchGroup(CurrentThreadContext.getCurrentSysCd(), CurrentThreadContext.getCurrentOrgCd(), codeGrpCd);
        if (CollectionUtils.isNotEmpty(sysDictionaryDTOList)) {
            for (SysDictionaryDTO sysDictionaryDTO : sysDictionaryDTOList) {
                if (!buOrgCds.contains(sysDictionaryDTO.getCodeDesc())) {
                    buOrgCds.add(sysDictionaryDTO.getCodeDesc());
                }
            }
        }
        if (!SplSystemConstant.DEFAULT_ORG_CD.equals(CurrentThreadContext.getCurrentBuOrgCd())) {
            if (CollectionUtils.isEmpty(buOrgCds) || buOrgCds.size() == BaseConstant.IS_YESNO_NO) {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "流程权限变更配置不能为空.");
            }
            if (buOrgCds.contains(currBuOrgCd)) {
                buOrgCds = new ArrayList<>(BaseConstant.IS_YESNO_YES);
                buOrgCds.add(currBuOrgCd);
            } else {
                throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "当前所在事业部不支持流程权限变更配置.");
            }
        }

        for (String buOrgCd : buOrgCds) {
            String key = "pDefKey" + buOrgCd;
            String pDefKeyJSON = request.getParameter(key);
            if (StringUtils.isNotEmpty(pDefKeyJSON)) {
                String[] pDefKeyStr = pDefKeyJSON.split(";");
                if (pDefKeyStr.length > BaseConstant.IS_YESNO_NO) {
                    for (String pDefKey : pDefKeyStr) {
                        SysBizFlowRlVO sysBizFlowRlVO = new SysBizFlowRlVO();
                        sysBizFlowRlVO.setDataId(Long.valueOf(dataId));
                        sysBizFlowRlVO.setTabNm(tabNm);
                        sysBizFlowRlVO.setPDefKey(pDefKey);
                        sysBizFlowRlVO.setBuOrgCd(buOrgCd);
                        sysBizFlowRlVO.setIsDel(BaseConstant.IS_YESNO_NO);
                        sysBizFlowRlVO.setIsValid(BaseConstant.IS_YESNO_YES);
                        sysBizFlowRlVO.setSysCd(StringUtils.isEmpty(CurrentThreadContext.getCurrentSysCd()) ? SplSystemConstant.FL_SYS_CD : CurrentThreadContext.getCurrentSysCd());
                        String flowNum = request.getParameter("flowNum" + pDefKey);
                        String flowNumcheckb = request.getParameter("flowNumcheckb");
                        if (StringUtils.isNotEmpty(flowNum)) {
                            sysBizFlowRlVO.setFlowNum(Integer.valueOf(flowNum));
                        }
                        String expireUncardNum = request.getParameter("expire" + pDefKey);
                        if (StringUtils.isNotEmpty(expireUncardNum)) {
                            sysBizFlowRlVO.setExpireUncardNum(Integer.valueOf(expireUncardNum));
                        }
                        if (pDefKey.equalsIgnoreCase(SysBizFlowRlConstant.CODE_BIZ_FLOW_P_DEF_KEY_2)) {
                            if ("true".equals(flowNumcheckb)) {
                                sysBizFlowRlVO.setFlowNum(Integer.valueOf(-1));
                            }
                        }
                        list.add(sysBizFlowRlVO);
                    }
                }
            }
        }

        if (CollectionUtils.isEmpty(list)) {
            throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_604, "请求数据为空.");
        }

        return list;
    }

    /**
     * 获取请求参数(新增)
     *
     * @param request
     * @return
     */
    private List<SysBizFlowRlVO> getRequestForParamAdd(HttpServletRequest request) throws BaseException {
        List<SysBizFlowRlVO> list = this.getRequestParam(request);
        if (CollectionUtils.isNotEmpty(list)) {
            for (SysBizFlowRlVO sysBizFlowRlVO : list) {
                sysBizFlowRlVO.setIsDel(BaseConstant.IS_YESNO_NO);
                sysBizFlowRlVO.setCrtTm(new Date());
                sysBizFlowRlVO.setCrtUsrId(CurrentThreadContext.getCurrentUserId());
            }
        }
        return list;
    }
}

